package com.ruoyi.web.controller.laiqianba.applet;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.applet.enums.AppletEnum;
import com.ruoyi.applet.enums.StatusEnum;
import com.ruoyi.channel.service.IChannelBaseInfoService;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.db.domain.AppletConfigInfo;
import com.ruoyi.db.domain.ChannelBaseInfo;
import com.ruoyi.db.mapper.ChannelBaseInfoMapper;
import com.ruoyi.web.wrapper.AppletConfigInfoWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.applet.service.IAppletConfigInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 小程序配置Controller
 * 
 * @author ruoyi
 * @date 2024-12-27
 */
@RestController
@RequestMapping("/applet/applet")
public class AppletConfigInfoController extends BaseController
{
    @Autowired
    private IAppletConfigInfoService appletConfigInfoService;

    @Autowired
    IChannelBaseInfoService channelBaseInfoService;




    @GetMapping("/extDate")
    public AjaxResult extData(){
        JSONObject returnData = new JSONObject();
        returnData.put("statusTypeList", StatusEnum.getStatusTypeMapList());
        returnData.put("channelCodeList",channelBaseInfoService.getChannelNameList2());
        returnData.put("channelCodeAppList",channelBaseInfoService.getChannelNameList3());
        returnData.put("appletList", AppletEnum.getStatusTypeMapList());
        return AjaxResult.success(returnData);
    }



    /**
     * 查询小程序配置列表
     */
    @PreAuthorize("@ss.hasPermi('applet:applet:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppletConfigInfo appletConfigInfo)
    {
        startPage();
        List<Map<String, Object>> list = appletConfigInfoService.selectAppletConfigInfoMapList(appletConfigInfo);
        list = new AppletConfigInfoWrapper(list).wrap();
        return getDataTable(list);
    }

    /**
     * 导出小程序配置列表
     */
    @PreAuthorize("@ss.hasPermi('applet:applet:export')")
    @Log(title = "小程序配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppletConfigInfo appletConfigInfo)
    {
        List<AppletConfigInfo> list = appletConfigInfoService.selectAppletConfigInfoList(appletConfigInfo);
        ExcelUtil<AppletConfigInfo> util = new ExcelUtil<AppletConfigInfo>(AppletConfigInfo.class);
        util.exportExcel(response, list, "小程序配置数据");
    }

    /**
     * 获取小程序配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:applet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appletConfigInfoService.selectAppletConfigInfoById(id));
    }

    /**
     * 新增小程序配置
     */
    @PreAuthorize("@ss.hasPermi('applet:applet:add')")
    @Log(title = "小程序配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletConfigInfo appletConfigInfo)
    {

        AjaxResult ajaxResult = appletConfigInfoService.insertAppletConfigInfo(appletConfigInfo);

        return ajaxResult;
    }

    /**
     * 修改小程序配置
     */
    @PreAuthorize("@ss.hasPermi('applet:applet:edit')")
    @Log(title = "小程序配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletConfigInfo appletConfigInfo)
    {
        return toAjax(appletConfigInfoService.updateAppletConfigInfo(appletConfigInfo));
    }

    /**
     * 删除小程序配置
     */
    @PreAuthorize("@ss.hasPermi('applet:applet:remove')")
    @Log(title = "小程序配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appletConfigInfoService.deleteAppletConfigInfoByIds(ids));
    }

    /**
     * 查询小程序配置列表
     */
    @PreAuthorize("@ss.hasPermi('applet/browser/list')")
    @GetMapping("/listBrowser")
    public TableDataInfo listBrowser(AppletConfigInfo appletConfigInfo)
    {
        startPage();
        List<Map<String, Object>> list = appletConfigInfoService.selectAppletConfigInfoByH5MapList(appletConfigInfo);
        list = new AppletConfigInfoWrapper(list).wrap();
        return getDataTable(list);
    }

    @GetMapping("/app")
    public TableDataInfo listBrowser1(AppletConfigInfo appletConfigInfo)
    {
        startPage();
        List<Map<String, Object>> list = appletConfigInfoService.selectAppletConfigInfoByH5MapList1(appletConfigInfo);
        list = new AppletConfigInfoWrapper(list).wrap();
        return getDataTable(list);
    }

    @PutMapping("/updateAppletInfo")
    public AjaxResult  updateAppletInfo(@RequestBody AppletConfigInfo appletConfigInfo)
    {
        return toAjax(appletConfigInfoService.updateAppletInfo(appletConfigInfo));
    }

    @PutMapping("updateAppletInfoByH5")
    public AjaxResult updateAppletInfoByH5(@RequestBody AppletConfigInfo appletConfigInfo){
        return toAjax(appletConfigInfoService.updateAppletInfoByH5(appletConfigInfo));
    }

    @PutMapping("updateAppletInfoByApp")
    public AjaxResult updateAppletInfoByApp(@RequestBody AppletConfigInfo appletConfigInfo){
        return toAjax(appletConfigInfoService.updateAppletInfoByApp(appletConfigInfo));
    }
}
